import request from "@/utils/request";
import { AxiosPromise } from "axios";
import {
  OrderQuery,
  OrderPageResult,
  OrderForm,
  DataSummarization,
  PendingOrder,
  OverdueSituation,
} from "./types";

/**
 * 获取订单分页数据
 *
 * @param queryParams
 */
export function getOrderPage(
  queryParams?: OrderQuery
): AxiosPromise<OrderPageResult> {
  return request({
    url: "/api/v1/orders/page",
    method: "get",
    params: queryParams,
  });
}

/**
 * 获取订单详情
 *
 * @param id
 */
export function getOrderForm(id: number): AxiosPromise<OrderForm> {
  return request({
    url: "/api/v1/orders/" + id + "/form",
    method: "get",
  });
}

/**
 * 创建订单
 *
 * @param data
 */
export function addOrder(data: OrderForm) {
  return request({
    url: "/api/v1/orders",
    method: "post",
    data: data,
  });
}

/**
 * 修改订单
 *
 * @param id
 * @param data
 */
export function updateOrder(id: number, data: OrderForm) {
  return request({
    url: "/api/v1/orders/" + id,
    method: "put",
    data: data,
  });
}

/**
 * 撤销订单
 *
 * @param ids
 */
export function cancelOrder(ids: string) {
  return request({
    url: "/api/v1/orders/" + ids,
    method: "put",
  });
}
/*
 * 数据汇总
 * */
export function getDataSummarization(): AxiosPromise<DataSummarization> {
  return request({
    url: "/api/v1/orders/data_summarization",
    method: "get",
  });
}
/*
 * 待处理订单
 * */
export function getPendingOrder(): AxiosPromise<PendingOrder> {
  return request({
    url: "/api/v1/orders/pending_order",
    method: "get",
  });
}
/*
 * 逾期情况
 * */
export function getOverdueSituation(): AxiosPromise<OverdueSituation> {
  return request({
    url: "/api/v1/orders/overdue_situation",
    method: "get",
  });
}
